package com.leetcode;

/**
 * @author yijy
 * @description
 * @create 2021/3/9 下午4:18
 **/
public class SoulTest {


    public static void main(String[] args) {
        String s = "12.512";
        new SoulTest().StringConvertToDouble(s);
        char c = '1';
        int c1 = c;
        System.out.println(c1);
    }


    public Double StringConvertToDouble(String s) {
        if(null == s || "".equals(s)|| s.trim().length() < s.length()){
            throw new NumberFormatException("empty String");
        }
        double a = 0.0;
        String[] nums = s.split("\\.");
       for(int i=0; i< nums[0].length(); i++){
            switch (s.charAt(i)){
                case '0':
                    int j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                case '1':
                    j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                case '2':
                    j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                case '3':
                    j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                case '4':
                    j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                case '5':
                   j = Character.getNumericValue(nums[0].charAt(i));
                   a = a*10 +j;
                   break;
                case '6' :
                    j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                case '7' :
                    j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                case '8' :
                    j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                case '9' :
                    j = Character.getNumericValue(nums[0].charAt(i));
                    a = a*10 +j;
                    break;
                    default:
                        throw new NumberFormatException("非数字");

           }
       }
        double b = 0.0;
        for(int i=nums[1].length()-1; i>=0; i--){
            if('0' == nums[1].charAt(i)) {
                int j = Character.getNumericValue(nums[1].charAt(i));
                b = b/10 + j ;
            }else
            if('1' == nums[1].charAt(i)) {
                int j = Character.getNumericValue(nums[1].charAt(i));
                b = b/10 + j ;
            }else
            if('2' == nums[1].charAt(i)) {
                int j = Character.getNumericValue(nums[1].charAt(i));
                b = b/10 + j ;
            }else
            if('3' == nums[1].charAt(i)) {
                int j = Character.getNumericValue(nums[1].charAt(i));
                b = b/10 + j ;
            }else
            if('4' == nums[1].charAt(i)) {
                int j = Character.getNumericValue(nums[1].charAt(i));
                b = b/10 + j ;
            }else if('5' == nums[1].charAt(i)) {
                int j = Character.getNumericValue(nums[1].charAt(i));
                b = b/10 + j ;
            }else
            if('6' == nums[1].charAt(i)) {
                int j = Character.getNumericValue(nums[1].charAt(i));
                b = b/10 + j ;
            }
        }
        b = b/10;
        System.out.println(a+b);
        return a+b;
    }
}
